package org.testfire.model.assertions;

import org.testfire.model.HtmlFinderType;
import org.testfire.model.TestFireObject;
import org.testfire.model.TestsetType;
import org.testfire.util.DomUtil;
import org.testfire.translator.TranslatorFactory;
import org.w3c.dom.Element;

/**
 * Created by IntelliJ IDEA.
 * User: granum
 * Date: Sep 2, 2007
 * Time: 5:47:53 PM
 *
 */
public abstract class Assertion implements TestFireObject
{
    private String message;

    private HtmlFinderType finder;

    private TestFireObject parent;

    public Assertion( Element el )
    {
        this.parse( el );
    }

    public TestFireObject getParent()
    {
        return this.parent;
    }

    public void parse( Element el )
    {
        this.message = el.getAttribute( "message" );
        this.finder = new HtmlFinderType( DomUtil.getChildElement( el ) );
        message = getMessage() == null ? "" : getMessage();
    }

    public void setParent( TestFireObject parent )
    {

        this.parent = parent;
    }

    public Object translate( TestsetType testset )
    {
        return TranslatorFactory.translate(testset, this);        
    }

    public String getMessage()
    {
        return message;
    }

    public HtmlFinderType getFinder()
    {
        return finder;
    }
}
